<template>
    <view
        @tap="__e"
        @touchmove.stop.prevent="__e"
        class="mask data-v-7244a36e"
        :data-event-opts="[
            ['tap', [['cancel', ['$event']]]],
            ['touchmove', [['', ['$event']]]]
        ]"
    >
        <view @tap.stop.prevent="__e" class="mask-content animated bounceInUp data-v-7244a36e" :data-event-opts="[['tap', [['', ['$event']]]]]">
            <text @tap="__e" class="new-iconfont icon-close close-btn data-v-7244a36e" :data-event-opts="[['tap', [['cancel', ['$event']]]]]"></text>
            <view class="title data-v-7244a36e">{{ '' + info.box.title + '' }}</view>
            <view class="block data-v-7244a36e">
                <view class="item-title data-v-7244a36e">单价:</view>
                <view class="price-c data-v-7244a36e">
                    <price-display @__l="__l" class="data-v-7244a36e" :info="info.box" vueId="76c74da0-1"></price-display>
                </view>
            </view>
            <view class="block data-v-7244a36e">
                <view class="item-title data-v-7244a36e">数量:</view>
                <view class="total-list data-v-7244a36e">
                    <view @tap="__e" :class="['item', 'data-v-7244a36e', payTotal === 1 ? 'actived' : '']" :data-event-opts="[['tap', [['e0', ['$event']]]]]">开1个</view>
                    <view
                        @tap="__e"
                        :class="['item', 'data-v-7244a36e', payTotal === 0 ? 'actived' : '']"
                        :data-event-opts="[['tap', [['e1', ['$event']]]]]"
                        v-if="info.box.sku_ratio_type === 1"
                    >
                        {{ '整盒端(' + info.box.sku_total + '个)' }}
                    </view>
                    <view @tap="__e" :class="['item', 'data-v-7244a36e', payTotal === 5 ? 'actived' : '']" :data-event-opts="[['tap', [['e2', ['$event']]]]]" v-else>连开5个</view>
                    <view @tap="__e" :class="['item', 'data-v-7244a36e', payTotal === 10 ? 'actived' : '']" :data-event-opts="[['tap', [['e3', ['$event']]]]]">连开10个</view>
                </view>
            </view>
            <view class="block data-v-7244a36e">
                <view class="item-title data-v-7244a36e">可用优惠券:</view>
                <view @tap="__e" class="arrow-right bold data-v-7244a36e" :data-event-opts="[['tap', [['e4', ['$event']]]]]">
                    <text class="meta data-v-7244a36e" v-if="order.coupon_discount">{{ '- ¥' + $root.g0 }}</text>
                    <block v-else>
                        <text class="meta data-v-7244a36e" style="color: #ff1a1a" v-if="$root.g1">{{ $root.g2 + '张可用' }}</text>
                        <text class="meta gray-text data-v-7244a36e" v-else>暂无可用优惠券</text>
                    </block>
                    <text class="new-iconfont icon-arrow-right data-v-7244a36e"></text>
                </view>
            </view>
            <view class="block data-v-7244a36e">
                <view class="item-title data-v-7244a36e">可用红包:</view>
                <view class="arrow-right bold data-v-7244a36e">
                    <block v-if="order.redpack">
                        <text class="meta data-v-7244a36e">{{ '¥' + $root.g3 }}</text>
                        <switch
                            @change="__e"
                            :checked="order.is_use_redpack"
                            class="redpack-switch data-v-7244a36e"
                            :data-event-opts="[['change', [['switchChange', ['$event']]]]]"
                        ></switch>
                    </block>
                    <text class="meta data-v-7244a36e" v-else>¥0</text>
                </view>
            </view>
            <view class="block data-v-7244a36e" v-if="order.max_useable_score">
                <view class="item-title data-v-7244a36e">{{ '' + scoreAlias + '抵扣' }}</view>
                <view class="arrow-right bold data-v-7244a36e">
                    <text class="meta data-v-7244a36e">{{ '' + order.max_useable_score + scoreAlias }}</text>
                    <text class="meta red data-v-7244a36e" style="margin-left: 10rpx" v-if="order.score_discount">{{ '-¥' + $root.f0 }}</text>
                    <switch
                        @change="__e"
                        :checked="order.is_use_score"
                        class="redpack-switch data-v-7244a36e"
                        :data-event-opts="[['change', [['scoreSwitchChange', ['$event']]]]]"
                        v-if="order.max_useable_score"
                    ></switch>
                </view>
            </view>
            <view class="total data-v-7244a36e">
                小计：
                <price-display @__l="__l" class="data-v-7244a36e" :info="order" prefix="pay_" vueId="76c74da0-2"></price-display>
            </view>
            <user-statement
                @__l="__l($event, { eventOpts: [['^input', [['__set_model', ['', 'isCheckUserStatement', '$event', []]]]]] })"
                @input="__e($event, { eventOpts: [['^input', [['__set_model', ['', 'isCheckUserStatement', '$event', []]]]]] })"
                class="data-v-7244a36e"
                :data-event-opts="[['^input', [['__set_model', ['', 'isCheckUserStatement', '$event', []]]]]]"
                :value="isCheckUserStatement"
                vueId="76c74da0-3"
            ></user-statement>
            <view class="button-c data-v-7244a36e">
                <view
                    @tap="__e"
                    class="button data-v-7244a36e"
                    :data-event-opts="[['tap', [['disableMultiClick', ['$0'], ['submit']]]]]"
                    v-if="isInit && !isSubmiting && isCheckUserStatement"
                >
                    <text class="data-v-7244a36e">确认购买</text>
                </view>
                <view class="button disabled data-v-7244a36e" v-else>
                    <text class="data-v-7244a36e">确认购买</text>
                </view>
            </view>
        </view>
        <usable-coupon-popup
            @__l="
                __l($event, {
                    eventOpts: [
                        ['^change', [['couponChange']]],
                        ['^close', [['e5']]]
                    ]
                })
            "
            @change="
                __e($event, {
                    eventOpts: [
                        ['^change', [['couponChange']]],
                        ['^close', [['e5']]]
                    ]
                })
            "
            @close="
                __e($event, {
                    eventOpts: [
                        ['^change', [['couponChange']]],
                        ['^close', [['e5']]]
                    ]
                })
            "
            class="data-v-7244a36e"
            :data-event-opts="[
                ['^change', [['couponChange']]],
                ['^close', [['e5']]]
            ]"
            :unusableCoupons="unusableCoupons"
            :usableCoupons="usableCoupons"
            vueId="76c74da0-4"
            v-if="isCouponPopup"
        ></usable-coupon-popup>
    </view>
</template>

<script>
import priceDisplay from '@/components/PriceDisplay/PriceDisplay';
import userStatement from '@/components/UserStatement/UserStatement';
import usableCouponPopup from '@/components/UsableCouponPopup/UsableCouponPopup';
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/openBox/components/PayCard'],
    {
        '3d7e': function (e, t, o) {
            'use strict';

            o.d(t, 'b', function () {
                return i;
            });
            o.d(t, 'c', function () {
                return r;
            });
            o.d(t, 'a', function () {
                return n;
            });
            var n = {
                PriceDisplay: function () {
                    return o.e('components/PriceDisplay/PriceDisplay').then(o.bind(null, '6b05'));
                },
                UserStatement: function () {
                    return o.e('components/UserStatement/UserStatement').then(o.bind(null, '72e8'));
                },
                UsableCouponPopup: function () {
                    return o.e('components/UsableCouponPopup/UsableCouponPopup').then(o.bind(null, '3858'));
                }
            };
            var i = function () {
                var that = this;
                var t = (that.$createElement, that._self._c, that.order.coupon_discount ? that.$tool.formatPrice(that.order.coupon_discount) : null);
                if (that.order.coupon_discount) {
                    var o = null;
                } else {
                    var o = that.usableCoupons.length;
                }
                if (!that.order.coupon_discount && o) {
                    var n = that.usableCoupons.length;
                } else {
                    var n = null;
                }
                var i = that.order.redpack ? that.$tool.formatPrice(that.order.redpack) : null;
                var r = that.order.max_useable_score && that.order.score_discount ? that._f('priceToFixed')(that.order.score_discount) : null;
                that._isMounted ||
                    ((that.e0 = function (t) {
                        that.payTotal = 1;
                    }),
                    (that.e1 = function (t) {
                        that.payTotal = 0;
                    }),
                    (that.e2 = function (t) {
                        that.payTotal = 5;
                    }),
                    (that.e3 = function (t) {
                        that.payTotal = 10;
                    }),
                    (that.e4 = function (t) {
                        that.isCouponPopup = true;
                    }),
                    (that.e5 = function (t) {
                        that.isCouponPopup = false;
                    }));
                that.$mp.data = Object.assign(
                    {},
                    {
                        $root: {
                            g0: t,
                            g1: o,
                            g2: n,
                            g3: i,
                            f0: r
                        }
                    }
                );
            };
            var r = [];
        },
        7835: function (e, t, o) {
            'use strict';

            o.r(t);
            var n = o('3d7e');
            var i = o('ced5');
            for (var r in i) {
                if (['default'].indexOf(r) < 0) {
                    (function (e) {
                        o.d(t, e, function () {
                            return i[e];
                        });
                    })(r);
                }
            }
            o('de4a');
            var u = o('f0c5');
            var c = Object(u.a)(i.default, n.b, n.c, false, null, '7244a36e', null, false, n.a, void 0);
            t.default = c.exports;
        },
        '8b2e': function (e, t, o) {},
        ced5: function (e, t, o) {
            'use strict';

            o.r(t);
            var n = o('fbe1');
            var i = o.n(n);
            for (var r in n) {
                if (['default'].indexOf(r) < 0) {
                    (function (e) {
                        o.d(t, e, function () {
                            return n[e];
                        });
                    })(r);
                }
            }
            t.default = i.a;
        },
        de4a: function (e, t, o) {
            'use strict';

            var n = o('8b2e');
            o.n(n).a;
        },
        fbe1: function (e, t, o) {
            'use strict';

            (function (e) {
                var n = o('4ea4');
                Object.defineProperty(t, '__esModule', {
                    value: true
                });
                t.default = void 0;
                var i = n(o('9523'));
                var r = n(o('82c0'));
                function u(e, t) {
                    var o = Object.keys(e);
                    if (Object.getOwnPropertySymbols) {
                        var n = Object.getOwnPropertySymbols(e);
                        if (t) {
                            n = n.filter(function (t) {
                                return Object.getOwnPropertyDescriptor(e, t).enumerable;
                            });
                        }
                        o.push.apply(o, n);
                    }
                    return o;
                }
                function c(e) {
                    for (var t = 1; t < arguments.length; t++) {
                        var o = null != arguments[t] ? arguments[t] : {};
                        t % 2
                            ? u(Object(o), true).forEach(function (t) {
                                  (0, i.default)(e, t, o[t]);
                              })
                            : Object.getOwnPropertyDescriptors
                            ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(o))
                            : u(Object(o)).forEach(function (t) {
                                  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(o, t));
                              });
                    }
                    return e;
                }
                var a = {
                    components: {},
                    data: function () {
                        return {
                            payTotal: 1,
                            order: {},
                            price: 0,
                            form: {
                                is_use_redpack: 'unselect',
                                is_use_score: 0
                            },
                            currentCoupon: {},
                            isCouponPopup: false,
                            unusableCoupons: [],
                            usableCoupons: [],
                            isCheckUserStatement: true,
                            isInit: false,
                            isSubmiting: false
                        };
                    },
                    props: {
                        info: {
                            type: Object
                        },
                        buyTotal: {
                            type: Number
                        }
                    },
                    computed: {},
                    watch: {
                        payTotal: function () {
                            this.initOrder();
                        }
                    },
                    onLoad: function (e) {},
                    created: function () {
                        this.payTotal = this.buyTotal;
                        this.initOrder();
                    },
                    methods: {
                        couponChange: function (e) {
                            e.id === this.currentCoupon.id || ((this.currentCoupon = e), this.initOrder());
                        },
                        initOrder: function () {
                            var that = this;
                            e.showLoading();
                            this.$http(
                                '/box-order/preview',
                                'POST',
                                c(
                                    {
                                        room_id: this.info.room.id,
                                        sku_index: this.info.sku_index,
                                        page_uuid: this.info.page_uuid,
                                        coupon_id: this.currentCoupon.id,
                                        total: this.payTotal
                                    },
                                    this.form
                                )
                            )
                                .then(function (o) {
                                    that.isInit = true;
                                    that.order = o.data.order;
                                    that.unusableCoupons = o.data.order.coupons.unusable;
                                    that.usableCoupons = o.data.order.coupons.usable;
                                    e.hideLoading();
                                })
                                .catch(function (e) {
                                    that.isInit = false;
                                    that.cancel();
                                });
                        },
                        switchChange: function (e) {
                            this.form.is_use_redpack = e.detail.value ? 1 : 0;
                            this.initOrder();
                        },
                        scoreSwitchChange: function (e) {
                            this.form.is_use_score = e.detail.value ? 1 : 0;
                            this.initOrder();
                        },
                        cancel: function () {
                            this.$emit('cancel');
                        },
                        createOrder: function () {
                            var that = this;
                            e.showLoading({
                                title: '提交中'
                            });
                            this.isSubmiting = true;
                            this.$http(
                                '/box-order/confirm',
                                'POST',
                                c(
                                    {
                                        room_id: this.info.room.id,
                                        sku_index: this.info.sku_index,
                                        page_uuid: this.info.page_uuid,
                                        coupon_id: this.currentCoupon.id,
                                        total: this.payTotal
                                    },
                                    this.form
                                )
                            )
                                .then(function (o) {
                                    that.isSubmiting = false;
                                    e.hideLoading();
                                    var n = o.data;
                                    n.is_need_pay
                                        ? r.default.pay(
                                              c(
                                                  c({}, n),
                                                  {},
                                                  {
                                                      success: function () {
                                                          that.$emit('success', n.order);
                                                      },
                                                      fail: function () {
                                                          e.showToast({
                                                              title: '支付失败',
                                                              icon: 'none'
                                                          });
                                                          that.$http('/orders/'.concat(n.order.uuid), 'PUT', {
                                                              type: 'close_and_delete'
                                                          });
                                                      }
                                                  }
                                              )
                                          )
                                        : that.$emit('success', n.order);
                                })
                                .catch(function (e) {
                                    that.isSubmiting = false;
                                });
                        },
                        submit: function () {
                            var that = this;
                            e.requestSubscribeMessage({
                                tmplIds: [this.miniappSubscribeIds.order_delivered, this.miniappSubscribeIds.order_paid],
                                complete: function (e) {
                                    that.createOrder();
                                }
                            });
                        },
                        createAgentPay: function () {
                            e.showLoading({
                                title: '提交中',
                                icon: 'none'
                            });
                            this.$http(
                                '/box-order/confirm',
                                'POST',
                                c(
                                    {
                                        create_mode: 'agent_pay',
                                        room_id: this.info.room.id,
                                        sku_index: this.info.sku_index,
                                        page_uuid: this.info.page_uuid,
                                        coupon_id: this.currentCoupon.id,
                                        total: this.payTotal
                                    },
                                    this.form
                                )
                            ).then(function (t) {
                                e.hideLoading();
                                var o = t.data.uuid;
                                e.redirectTo({
                                    url: '/pages/agentPayRecord/detail?uuid=' + o
                                });
                            });
                        },
                        submitForDaifu: function () {
                            var that = this;
                            e.showModal({
                                title: '代付订单在生成后30分钟内可以转发给朋友帮你支付',
                                confirmText: '生成代付',
                                success: function (e) {
                                    if (e.confirm) {
                                        that.createAgentPay();
                                    }
                                }
                            });
                        }
                    },
                    onPageScroll: function (e) {}
                };
                t.default = a;
            }.call(this, o('543d').default));
        }
    }
]);
(global.webpackJsonp = global.webpackJsonp || []).push([
    'pages/openBox/components/PayCard-create-component',
    {
        'pages/openBox/components/PayCard-create-component': function (e, t, o) {
            o('543d').createComponent(o('7835'));
        }
    },
    [['pages/openBox/components/PayCard-create-component']]
]);
</script>
<style>
@import './PayCard.css';
</style>
